/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.olap;

import mondrian.olap.Member;
import mondrian.olap.Property;


/**
 * Member formatter that converts the actual member key into a key, prefixed by a given prefix. This key is looked
 * up in the i18n files.
 *
 * @author <a href="mailto:malonso@silenus-consultoria.es">Mariano Alonso</a>
 *
 * @since 14-abr-2009 20:21:21
 */
public abstract class PrefixMemberFormatter extends BaseMemberFormatter {
	/**
	 * The prefix.
	 */
	private final String prefix;

/**
   * Constructor.
   *
   * @param prefix the prefix.
   */
	protected PrefixMemberFormatter(final String prefix) {
		this.prefix = prefix;
	}

	/**
	 * Retrieves the key.
	 *
	 * @param member the member.
	 *
	 * @return the key.
	 */
	protected String getKey(final Member member) {
		String name = null;

		if(member != null) {
			Object key = member.getPropertyValue(Property.KEY.name);

			if(key != null) {
				name = prefix + key.toString();
			}
		}

		return name;
	}
}
